#pragma once

#include <pthread.h>

class Mutex
{
public:
    Mutex(pthread_mutex_t* pmtx)
        : _pmtx(pmtx)
    {}

    ~Mutex()
    {}

    void Lock()
    {
        pthread_mutex_lock(_pmtx);
    }

    void Unlock()
    {
        pthread_mutex_unlock(_pmtx);
    }

private:
    pthread_mutex_t* _pmtx;
};

// RAII风格的加锁方式
// 构造时自动进行加锁
// 析构时自动进行解锁
class lockGuard
{
public:
    lockGuard(pthread_mutex_t* pmtx)
        : _mtx(pmtx)
    {
        _mtx.Lock();
    }

    ~lockGuard()
    {
        _mtx.Unlock();
    }

private:
    Mutex _mtx;
};